<?php
function rsaVerify($data, $ali_public_key_path, $sign)  {
	$pubKey = file_get_contents($ali_public_key_path);
    $res = openssl_get_publickey($pubKey);
    $result = (bool)openssl_verify($data, base64_decode($sign), $res);
    openssl_free_key($res);    
    return $result;
}

function argSort($para) {
	ksort($para);
	reset($para);
	return $para;
}

function createLinkstring($para) {
	$arg  = "";
	while (list ($key, $val) = each ($para)) {
		$arg.=$key."=".$val."&";
	}
	//去掉最后一个&字符
	$arg = substr($arg,0,count($arg)-2);
	
	//如果存在转义字符，那么去掉转义
	if(get_magic_quotes_gpc()){$arg = stripslashes($arg);}
	
	return $arg;
}

$para_filter = array(
 'is_success'=> 'T',
 // 'notify_id'=> 'RqPnCoPT3K9%2Fvwbh3InXS9t%2FSwDciPp9gFtxlGdB8scp54Q0elZXh8WUsHoXUCR184WZ',
 'notify_id'=> 'RqPnCoPT3K9/vwbh3InXS9t/SwDciPp9gFtxlGdB8scp54Q0elZXh8WUsHoXUCR184WZ',
 'notify_time'=> '2016-05-06 11:20:08',
 'notify_type'=> 'trade_status_sync',
 'out_trade_no'=> '201656111953870',
 'payment_type'=> '1',
 'seller_id'=> '2088021819092242',
 'service'=> 'alipay.wap.create.direct.pay.by.user',
 'subject'=> '测试',
 'total_fee'=> '0.01',
 'trade_no'=> '2016050621001004760221926551',
 'trade_status'=> 'TRADE_SUCCESS'
);
		
		//对待签名参数数组排序
		$para_sort = argSort($para_filter);
		var_dump($para_sort);
		
		//把数组所有元素，按照“参数=参数值”的模式用“&”字符拼接成字符串
		$prestr = createLinkstring($para_sort);

$data = $prestr;

$data = <<<Si
_input_charset=utf-8&notify_url=http://www.lyqz365.com/app/pay/notify_url.php&out_trade_no=201655163631631&partner=2088021819092242&payment_type=1&return_url=http://www.lyqz365.com/app/pay/return_url.php&seller_id=2088021819092242&service=alipay.wap.create.direct.pay.by.user&subject=测试&total_fee=0.01
Si;

$sign = 'pyyoQYaNMaglMkeA69WfBsIRdFof2gN7s0ivszs4Y8K9W/Kv7JTy8fE1ROn3okJ8810CUasdlVJDAD3SooKn1dIzo/mgs6oA/0SxhMTjQbQ+Tqnqn65CuaHqhOc3nhBLKg+Oe+wfHqlZOBxgNpDEomFf9Xkj/ZPogKfAVXkF2P0=';


var_dump(base64_encode($data));


var_dump(rsaVerify($data, 'key/rsa_public_key.pem', $sign));